/* 验证不能为空 */
const validatorIsEmpty = (value, callback) => {
  // if ((!value) || value === '' || (value.length === 0)) {
  //   callback(false, '输入内容不能为空');
  // } else {
  //   callback(true);
  // }
  callback(true);
};

/* 验证只能是不小于零的整数 */
const validatorNumber = (value, callback) => {
  const reg = /^([1-9]\d*|0)$/;
  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '输入内容不能为空');
    callback(true);
  } else if (!reg.test(value)) {
    callback(false, '请输入不小于0的整数');
  } else {
    callback(true);
  }
};

/* 验证只能是不小于零的数 */
const validatorNumberNotLessThan0 = (value, callback) => {
  const reg1 = /(^([1-9]\d*|0)(\.[0-9]*)?$)/;
  const reg2 = /(^([1-9]\d*|0)(\.[0-9]{1,2})?$)/;
  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '输入内容不能为空');
    callback(true);
  } else if (Number(value) < 0) {
    callback(false, '请输入不小于0的数');
  } else if (!reg1.test(value)) {
    callback(false, '请输入正确的数字格式');
  } else if (!reg2.test(value)) {
    callback(false, '不可超过两位小数');
  } else {
    callback(true);
  }
};

/* 验证只能在0-50字符 */
const validatorIs0To50Byte = (value, callback) => {
  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '输入内容不能为空');
    callback(true);
  } else if (String(value).replace(/\s/g, '').length > 50) {
    callback(false, '字数不能超过50个字');
  } else {
    callback(true);
  }
};
/* 验证只能在0-100字符 */
const validatorIs0To100Byte = (value, callback) => {
  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '输入内容不能为空');
    callback(true);
  } else if (String(value).replace(/\s/g, '').length > 100) {
    callback(false, '字数不能超过100个字');
  } else {
    callback(true);
  }
};
/* 验证只能在0-200字符 */
const validatorIs0To200Byte = (value, callback) => {
  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '输入内容不能为空');
    callback(true);
  } else if (String(value).replace(/\s/g, '').length > 200) {
    callback(false, '字数不能超过200个字');
  } else {
    callback(true);
  }
};

/* 验证只能在0-16汉字 */
const validatorIs0To16Byte = (value, callback) => {
  const reg = /^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/;
  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '输入内容不能为空');
    callback(true);
  } else if (String(value).replace(/\s/g, '').length > 16) {
    callback(false, '字数不能超过16个字');
  } else if (!reg.test(value)) {
    callback(false, '只能输入中文');
  } else {
    callback(true);
  }
};

/* 手机号验证 */
const validatorPhone = (value, callback) => {
  const reg = /^((0\d{2,3}-)?([2-9][0-9]{6,7})(-[0-9]{1,4})?)$|^(1[3456789]\d{9})$|^((400)-(\d{3})-(\d{4}))$|^((400)(\d{3})(\d{4}))$/;

  if ((!value) || value === '' || (value.length === 0)) {
    // callback(false, '请输入手机号');
    callback(true);
  } else if (!reg.test(value)) {
    callback(false, '联系电话格式不正确');
  } else {
    callback(true);
  }
};

const rules = {
  // 事件基本信息
  eventBasicData: {
    name: { validator: validatorIsEmpty },
    address: { validator: validatorIsEmpty },
    casualty: { validator: validatorNumber },
    assetLoss: { validator: validatorNumberNotLessThan0 },
    describe: { validator: validatorIs0To100Byte }
  },
  // 上报人信息
  reportData: {
    name: { validator: validatorIs0To16Byte },
    phone: { validator: validatorPhone },
    describe: { validator: validatorIs0To100Byte }
  },
  // 指挥人员信息
  commandData: {
    job: { validator: validatorIsEmpty },
    phone: { validator: validatorPhone }
  },
  // 归档总结
  fileSummary: {
    summary: { validator: validatorIs0To200Byte },
    summaryHuman: { validator: validatorIs0To16Byte }
  },
  // 添加过程
  addRecord: {
    content: { validator: validatorIs0To200Byte }
  },
  // 应急助手一键通知消息提示
  assistant: {
    content: { validator: validatorIs0To50Byte }
  }
};

export default rules;
